package cn.mhome.merchant.framework.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.mhome.merchant.entity.clazz.param.ClassTypeParam;
import cn.mhome.merchant.entity.clazz.result.ClassTypeResult;
import cn.mhome.merchant.entity.common.result.CommonResult;
import cn.mhome.merchant.entity.common.result.DataResult;
import cn.mhome.merchant.entity.common.result.Pager;
import cn.mhome.merchant.server.clazz.service.ClassTypeService;

/**
 * 类别管理
 * @author lvpeng
 */
@Controller
@RequestMapping("/api/classtype")
public class ClassTypeController {
	
	
	@Resource
	private ClassTypeService classTypeService;
	
	/**
	 * 查询类别列表
	 * @param sysUserParam
	 * @return
	 */
	@RequestMapping(value = "/findForPage", method = { RequestMethod.POST,
			RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public DataResult findForPage(@RequestBody ClassTypeParam classTypeParam){
		DataResult dataResult = new DataResult();
		try {
			Pager<ClassTypeResult> data = classTypeService.findForPage(classTypeParam);
			dataResult.setData(data);
		} catch (Exception e) {
			dataResult.setCode(500);
			dataResult.setMsg("查询类别列表异常");
		}
		return dataResult;
	}
	
	/**
	 * 查询类别列表
	 * @param sysUserParam
	 * @return
	 */
	@RequestMapping(value = "/findSuperClassList", method = { RequestMethod.POST,
			RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public DataResult findSuperClassList(){
		DataResult dataResult = new DataResult();
		try {
			List<ClassTypeResult> data = classTypeService.findSuperClassList();
			dataResult.setData(data);
		} catch (Exception e) {
			dataResult.setCode(500);
			dataResult.setMsg("查询类别列表异常");
		}
		return dataResult;
	}
	
	/**
	 * 查询类别列表
	 * @param sysUserParam
	 * @return
	 */
	@RequestMapping(value = "/save", method = { RequestMethod.POST,
			RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public DataResult save(@RequestBody ClassTypeParam classTypeParam){
		DataResult dataResult = new DataResult();
		try {
			CommonResult result = classTypeService.save(classTypeParam);
			dataResult.setData(result);
		} catch (Exception e) {
			dataResult.setCode(500);
			dataResult.setMsg("保存异常");
		}
		return dataResult;
	}
	

	/**
	 * 查询类别列表
	 * @param sysUserParam
	 * @return
	 */
	@RequestMapping(value = "/deleteById", method = { RequestMethod.POST,
			RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public DataResult deleteById(@RequestBody ClassTypeParam classTypeParam){
		DataResult dataResult = new DataResult();
		try {
			CommonResult result = classTypeService.delete(classTypeParam);
			dataResult.setData(result);
		} catch (Exception e) {
			dataResult.setCode(500);
			dataResult.setMsg("删除异常");
		}
		return dataResult;
	}
}
